package com.archeanx.libx.adapter.binding

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.IdRes
import androidx.annotation.LayoutRes
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView


class XRvBindingHolder(var context: Context, private val binding: ViewDataBinding) : RecyclerView.ViewHolder(binding.root) {

    companion object {
        fun createHolder(parent: ViewGroup, @LayoutRes layoutId: Int): XRvBindingHolder {
            return XRvBindingHolder(parent.context, DataBindingUtil.inflate(LayoutInflater.from(parent.context), layoutId, parent, false))
        }
    }

    fun <B : ViewDataBinding> getBinding(): B =binding as B

    fun <V : View> findView(@IdRes id: Int): V = itemView.findViewById(id)

}